﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace proj3
{
    public partial class PltForm : System.Windows.Forms.Form
    {
        public PltForm()
        {
            InitializeComponent();
            for (int i = 0; i < Program.nameList.Count; i++)
                listBox.Items.Add(Program.nameList[i].name + "," + Program.nameList[i].year + "\n");

        }

        private void exitbtn_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void addbtn_Click(object sender, EventArgs e)
        {
            //namelist.Add(new Philosopher(""));
            Addform add = new Addform();
            add.Show();
        }

        private void delbtn_Click(object sender, EventArgs e)
        {
            // index has to be valid
            if (listBox.SelectedIndex < 0)
                return;
            Delform del = new Delform(listBox.SelectedIndex);
            del.Show();
            listBox.Items.Clear();
            /*for (int i = 0; i < Program.nameList.Count; i++)
            {
                Console.Write(Program.nameList[i].name + "," + Program.nameList[i].year + "\n");
                listBox.Items.Add(Program.nameList[i].name + "," + Program.nameList[i].year + "\n");
            }*/
        }

        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            nametxt.Text = Program.nameList[listBox.SelectedIndex].name;
            yeartxt.Text = Program.nameList[listBox.SelectedIndex].year;
            countrytxt.Text = Program.nameList[listBox.SelectedIndex].country;
            worktxt.Text = Program.nameList[listBox.SelectedIndex].work;
            summarytxt.Text = Program.nameList[listBox.SelectedIndex].summary;
            linktxt.Text = Program.nameList[listBox.SelectedIndex].link;
        }

        private void editbtn_Click(object sender, EventArgs e)
        {

        }
    }
}
